<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>
<script>

    function ajax(url) {
        return new Promise(function (resolve, reject) {
            var xhr = new XMLHttpRequest()
            xhr.open('GET', url)
            xhr.onload = function () {
                if (this.status === 200) {
                    resolve(this.response)
                } else {
                    reject(new Error(this.statusText))
                }
            }
            xhr.send()
        })
    }

    //  let promise = ajax('https://gank.io/api/data/Android/10/1')

    // promise.then((value)=>{
    //     console.log(111)
    // }).then((value)=>{
    //     console.log(222)
    //     console.log(value) //undefined
    //     return 3
    // }).then((value)=>{
    //     console.log(333)
    //     console.log(value) //value是上一个promise对象返回的值，如果没有，则打印undefined
    //     return new Promise(function (){

    //     })
    // }).then((value)=>{
    //     console.log(444) //不会打印，因为返回的promise状态为pedding
    //     console.log(value)
    // })

    // promise = ajax('https://gank.io/api/data1/Android/10/1')

    // promise.then(res=>{
    //     console.log(res)
    // }).catch((res)=>{
    //     console.log(res)
    // })

    // promise.then(res=>{
    //     console.log(res)
    // }).then(undefined,(res)=>{
    //     console.log(res)
    // })

    // let promise = Promise.resolve('foo')

    let p1 = new Promise((resolve,reject)=>{
        resolve(123)
    })

    var p2 = p1.then((value)=>{
        console.log(value)
        return p2
    })

    p2.then(res=>{

    },(res)=>{
        console.log(res)
    })

</script>

</html>